//
//  HCMineNameViewController.m
//  HappyChildren
//
//  Created by WillyZhao on 2017/1/2.
//  Copyright © 2017年 WillyZhao. All rights reserved.
//

#import "HCMineNameViewController.h"

@interface HCMineNameViewController () {
    UITextField *name;
    MBProgressHUD *mine_hud;
    HCPopLoadingView *popLoading;
}

@end

@implementation HCMineNameViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.textTitle = @"修改昵称";
    
    self.dataRequest.delegate = self;
    
    [self setRightButtonText:@"保存"];
    
    [self setLeftButtonImage:@"happy_mine_LBackIMG"];
    
    self.centerView.frame = CGRectMake(self.centerView.frame.origin.x, self.centerView.frame.origin.y, self.centerView.frame.size.width, self.centerView.frame.size.height+49);
    
    name = [[UITextField alloc] initWithFrame:CGRectMake(5, 10, self.centerView.frame.size.width - 10, 40)];
    name.placeholder = @"请输入昵称";
    name.borderStyle = UITextBorderStyleRoundedRect;
    [self.centerView addSubview:name];
    
    UILabel *promptLabel = [[UILabel alloc] initWithFrame:CGRectMake(5, 51, self.centerView.frame.size.width-10, 20)];
    promptLabel.textColor = [UIColor blackColor];
    promptLabel.font = YBKSystemFont(YBKAdaptiveFont(9));
    promptLabel.text = @"最多只能输入16个字符";
    [self.centerView addSubview:promptLabel];
    
    // Do any additional setup after loading the view from its nib.
}

-(void)rightBtnAction:(UIButton *)btn {
    if ([PublicFunction isNull:name.text]) {
        [XHToast showBottomWithText:@"昵称不能为空"];
    }else{
//        mine_hud  = [MBProgressHUD showHUDAddedTo:centerView animated:YES];
        popLoading = [[HCPopLoadingView alloc] initWithFrame:[UIScreen mainScreen].bounds];
        [popLoading showAnimate];
        [self.dataRequest postHC_MineMsgEdit:HCGETUSER(@"userid") message:name.text withType:EDT_NAME];
    }
}

-(void)dataRequesterFinish:(DataRequester *)requester requesterWithType:(DataRequestType)aType receiveDictionary:(NSDictionary *)dictionary {
//    [mine_hud hide:YES];
    [popLoading hidden];
    if ([dictionary[@"stat"] integerValue] == 200) {
        [self.navigationController popViewControllerAnimated:YES];
        [XHToast showBottomWithText:@"昵称修改成功"];
    }else{
        [XHToast showBottomWithText:@"昵称修改失败"];
    }
}

-(void)dataRequesterFail:(DataRequester *)requester requesterWithType:(DataRequestType)aType receiveErrorDictionary:(NSDictionary *)dictionary {
    [mine_hud hide:YES];
    [XHToast showBottomWithText:@"昵称修改失败"];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
